﻿using Jay.Sc2.Bof.Lib.State;

namespace Jay.Sc2.Bof.Lib.Action.Terran
{
	public abstract class ActionUpgradeFromEngineeringBay : ActionUpgradeFromTerran
	{
		public ActionUpgradeFromEngineeringBay(int researchTime, int minerals, int gas) : base(researchTime, minerals, gas) { }

		public override TerranState.TerranProductionBuilding GetProductionBuilding(TerranState state) { return state.EngineeringBay; }

		public override IAction[,] Requirements
		{
			get
			{
				if (m_Requirements == null)
					m_Requirements = new IAction[,] { { ActionProduceRefinery.Instance, ActionProduceEngineeringBay.Instance } };
				return m_Requirements;
			}
		}
	}
	public class ActionUpgradeInfantryWeapons1 : ActionUpgradeFromEngineeringBay
	{
		public static ActionUpgradeInfantryWeapons1 Instance = new ActionUpgradeInfantryWeapons1();

		private ActionUpgradeInfantryWeapons1() : base(160, 100, 100) { }

		public override TerranState.TerranUpgrade GetUpgrade(TerranState state) { return state.InfantryWeapons1; }
		public override string EventName { get { return "ActionResearchedInfantryWeapons1"; } }
	}
	public class ActionUpgradeInfantryWeapons2 : ActionUpgradeFromEngineeringBay
	{
		public static ActionUpgradeInfantryWeapons2 Instance = new ActionUpgradeInfantryWeapons2();

		private ActionUpgradeInfantryWeapons2() : base(190, 175, 175) { }

		public override TerranState.TerranUpgrade GetUpgrade(TerranState state) { return state.InfantryWeapons2; }
		public override string EventName { get { return "ActionResearchedInfantryWeapons2"; } }

		public override bool IsInvalid(Jay.Sc2.Bof.Lib.State.IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return base.IsInvalid(bo) || !state.InfantryWeapons1.Have || (state.Factory.Total + state.FactoryReactor.Total + state.FactoryTechLab.Total == 0);
		}

		public override bool HaveTechnology(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return state.EngineeringBay.Count > 0 && state.InfantryWeapons1.Available && state.Factory.Count + state.FactoryReactor.Count + state.FactoryTechLab.Count > 0;
		}

		public override IAction[,] Requirements
		{
			get
			{
				if (m_Requirements == null)
					m_Requirements = new IAction[,] { {ActionUpgradeInfantryWeapons1.Instance, ActionProduceFactory.Instance } };
				return m_Requirements;
			}
		}

	}
	public class ActionUpgradeInfantryWeapons3 : ActionUpgradeFromEngineeringBay
	{
		public static ActionUpgradeInfantryWeapons3 Instance = new ActionUpgradeInfantryWeapons3();

		private ActionUpgradeInfantryWeapons3() : base(220, 250, 250) { }

		public override TerranState.TerranUpgrade GetUpgrade(TerranState state) { return state.InfantryWeapons3; }
		public override string EventName { get { return "ActionResearchedInfantryWeapons3"; } }

		public override bool IsInvalid(Jay.Sc2.Bof.Lib.State.IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return base.IsInvalid(bo) || state.InfantryWeapons3.Have || !state.InfantryWeapons2.Have;
		}

		public override bool HaveTechnology(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return state.EngineeringBay.Count > 0 && state.InfantryWeapons2.Available;
		}

		public override IAction[,] Requirements
		{
			get
			{
				if (m_Requirements == null)
					m_Requirements = new IAction[,] { { ActionUpgradeInfantryWeapons2.Instance } };
				return m_Requirements;
			}
		}
	}
	public class ActionUpgradeInfantryArmor1 : ActionUpgradeFromEngineeringBay
	{
		public static ActionUpgradeInfantryArmor1 Instance = new ActionUpgradeInfantryArmor1();

		private ActionUpgradeInfantryArmor1() : base(160, 100, 100) { }

		public override TerranState.TerranUpgrade GetUpgrade(TerranState state) { return state.InfantryArmor1; }
		public override string EventName { get { return "ActionResearchedInfantryArmor1"; } }
	}
	public class ActionUpgradeInfantryArmor2 : ActionUpgradeFromEngineeringBay
	{
		public static ActionUpgradeInfantryArmor2 Instance = new ActionUpgradeInfantryArmor2();

		private ActionUpgradeInfantryArmor2() : base(190, 175, 175) { }

		public override TerranState.TerranUpgrade GetUpgrade(TerranState state) { return state.InfantryArmor2; }
		public override string EventName { get { return "ActionResearchedInfantryArmor2"; } }

		public override bool IsInvalid(Jay.Sc2.Bof.Lib.State.IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return base.IsInvalid(bo) || !state.InfantryArmor1.Have || (state.Factory.Total + state.FactoryReactor.Total + state.FactoryTechLab.Total == 0);
		}

		public override bool HaveTechnology(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return state.EngineeringBay.Count > 0 && state.InfantryArmor1.Available && state.Factory.Count + state.FactoryReactor.Count + state.FactoryTechLab.Count > 0;
		}

		public override IAction[,] Requirements
		{
			get
			{
				if (m_Requirements == null)
					m_Requirements = new IAction[,] { { ActionUpgradeInfantryArmor1.Instance, ActionProduceFactory.Instance } };
				return m_Requirements;
			}
		}

	}
	public class ActionUpgradeInfantryArmor3 : ActionUpgradeFromEngineeringBay
	{
		public static ActionUpgradeInfantryArmor3 Instance = new ActionUpgradeInfantryArmor3();

		private ActionUpgradeInfantryArmor3() : base(220, 250, 250) { }

		public override TerranState.TerranUpgrade GetUpgrade(TerranState state) { return state.InfantryArmor3; }
		public override string EventName { get { return "ActionResearchedInfantryArmor3"; } }

		public override bool IsInvalid(Jay.Sc2.Bof.Lib.State.IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return base.IsInvalid(bo) || state.InfantryArmor3.Have || !state.InfantryArmor2.Have;
		}

		public override bool HaveTechnology(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return state.EngineeringBay.Count > 0 && state.InfantryArmor2.Available;
		}

		public override IAction[,] Requirements
		{
			get
			{
				if (m_Requirements == null)
					m_Requirements = new IAction[,] { { ActionUpgradeInfantryArmor2.Instance } };
				return m_Requirements;
			}
		}
	}
	public class ActionUpgradeHiSecAutoTracking : ActionUpgradeFromEngineeringBay
	{
		public static ActionUpgradeHiSecAutoTracking Instance = new ActionUpgradeHiSecAutoTracking();

		private ActionUpgradeHiSecAutoTracking() : base(80, 100, 100) { }

		public override TerranState.TerranUpgrade GetUpgrade(TerranState state) { return state.HiSecAutoTracking; }
		public override string EventName { get { return "ActionResearchedHiSecAutoTracking"; } }
	}
	public class ActionUpgradeNeosteelFrames : ActionUpgradeFromEngineeringBay
	{
		public static ActionUpgradeNeosteelFrames Instance = new ActionUpgradeNeosteelFrames();

		private ActionUpgradeNeosteelFrames() : base(110, 100, 100) { }

		public override TerranState.TerranUpgrade GetUpgrade(TerranState state) { return state.NeosteelFrames; }
		public override string EventName { get { return "ActionResearchedNeosteelFrames"; } }
	}
	public class ActionUpgradeBuildingArmor : ActionUpgradeFromEngineeringBay
	{
		public static ActionUpgradeBuildingArmor Instance = new ActionUpgradeBuildingArmor();

		private ActionUpgradeBuildingArmor() : base(140, 150, 150) { }

		public override TerranState.TerranUpgrade GetUpgrade(TerranState state) { return state.BuildingArmor; }
		public override string EventName { get { return "ActionResearchedBuildingArmor"; } }
	}
}
